package cn.nbt.busManage.dao.repository;

import cn.nbt.busManage.model.entity.News;
import cn.nbt.busManage.model.entity.Point;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;


@Repository
public interface NewsRepository extends JpaRepository<News,Integer> {

    /**
     * 根据作者名称查询新闻信息
     */
    @Query("select a from News a where CONCAT(a.author, '') like CONCAT('%', :author, '%')")
    List<News> findByAuthor(@Param("author") String author);

    /**
     * 更新新闻信息
     * @param author 作者
     * @param title 标题
     * @param content 内容
     * @param createTime 创建时间
     * @param updateTime 更新时间
     * @param id 新闻id
     */
    @Modifying
    @Query("update News a set a.author=:author,a.title=:title,a.content=:content,a.createTime=:createTime,a.updateTime=:updateTime where a.id=:id")
    void updateNews(@Param("author")String author, @Param("title")String title, @Param("content")String content, @Param("createTime") LocalDateTime createTime, @Param("updateTime")LocalDateTime updateTime, @Param("id") int id);
}
